home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 August / CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso / disc2 / patches / symantec / rtlinc.exe / PAGE.H < prev    next >
C/C++ Source or Header  |  1993-06-28  |  3KB  |  114 lines

  1. /*_ page.h   Mon May  1 1989   Modified by: Walter Bright */
  2.  
  3. #ifndef __PAGE_H
  4. #define __PAGE_H    1
  5.  
  6. #if __cplusplus
  7. extern "C" {
  8. #endif
  9.  
  10. #if __INTSIZE == 4
  11. #define __BF
  12. #else
  13. #define __BF far
  14. #endif
  15.  
  16. #define __PGOFF        sizeof(unsigned short)
  17.  
  18. #pragma pack(1)
  19.  
  20. struct Pageheader
  21. {
  22. /* private: */
  23.     unsigned short pagesize;    /* total size of this page        */
  24.     unsigned short maxsize;    /* max size of a free block in free list */
  25.     unsigned short allocp;    /* roving pointer for allocator        */
  26.     unsigned short bassize;    /* size of first block (0 so it is never allocated) */
  27.     unsigned short baslnk;    /* offset of next free block    */
  28. };
  29.  
  30. #pragma pack()
  31.  
  32. #define PAGEOVERHEAD    sizeof(struct Pageheader)
  33.  
  34. /*****************************************
  35.  * Allocate a block of data and clear it.
  36.  * Use:
  37.  *    unsigned page_calloc(void __BF *baseptr,unsigned size);
  38.  * Returns:
  39.  *    offset of allocated data else 0
  40.  */
  41.  
  42. unsigned __cdecl page_calloc(void __BF *baseptr,unsigned size);
  43.  
  44. /*****************************************
  45.  * Allocate a block of data.
  46.  *    unsigned page_malloc(void __BF *baseptr,unsigned size);
  47.  * Returns:
  48.  *    offset of allocated data else 0
  49.  */
  50.  
  51. unsigned __cdecl page_malloc(void __BF *baseptr,unsigned size);
  52.  
  53. /*****************************************
  54.  * Reallocate memory that was allocated by page_malloc() or page_calloc().
  55.  * Use:
  56.  *    unsigned page_realloc(void __BF *baseptr,unsigned p, unsigned nbytes)
  57.  * Returns:
  58.  *    0 error
  59.  *    else offset of reallocated memory
  60.  */
  61.  
  62. unsigned __cdecl page_realloc(void __BF *baseptr,unsigned p, unsigned nbytes);
  63.  
  64. /*****************************************
  65.  * Free memory that was allocated by page_malloc() or page_calloc().
  66.  * Use:
  67.  *    int page_free(void __BF *baseptr,unsigned p);
  68.  * Returns:
  69.  *    0    success
  70.  *    -1    error (baseptr is bad, or memory is corrupted)
  71.  */
  72.  
  73. int __cdecl page_free(void __BF *baseptr,unsigned p);
  74.  
  75. /*****************************************
  76.  * Determine size of largest free block in page.
  77.  *    unsigned page_maxfree(void __BF *baseptr);
  78.  */
  79.  
  80. unsigned __cdecl page_maxfree(void __BF *baseptr);
  81.  
  82. /*****************************************
  83.  * Initialize memory allocation system in a page.
  84.  *    unsigned page_initialize(void __BF *baseptr,unsigned pagesize);
  85.  * Returns:
  86.  *    size of largest allocatable block
  87.  */
  88.  
  89. unsigned __cdecl page_initialize(void __BF *baseptr,unsigned pagesize);
  90.  
  91. /*****************************************
  92.  * Return number of bytes allocated for chunk of memory that was
  93.  * allocated by page_malloc, page_calloc or page_realloc.
  94.  */
  95.  
  96. /*unsigned __cdecl page_size(void __BF *baseptr,unsigned p);*/
  97.  
  98. #define page_size(baseptr,p) \
  99.     (*(unsigned short __BF *)((char __BF *)(baseptr) + (p) - __PGOFF) - __PGOFF)
  100.  
  101. /****************************************
  102.  * Convert pointer to page and offset into that page into a void * pointer.
  103.  */
  104.  
  105. /*void __BF * near page_toptr(void __BF *baseptr,unsigned p);*/
  106.  
  107. #define page_toptr(baseptr,p)    (void __BF *)((char __BF *)(baseptr) + (p))
  108.  
  109. #if __cplusplus
  110. }
  111. #endif
  112.  
  113. #endif /* __PAGE_H */
  114.